import { ref } from 'vue'

// 对话框的
export function usePageModal() {
  const formModelRef = ref(null)
  // 编辑对话框中表单的数据
  const defualtModelFormData = ref({})
  // 监听添加事件
  const onHandleNewClick = () => {
    defualtModelFormData.value = {}
    formModelRef.value.dialogTitle = '添加'
    formModelRef.value.dialogVisible = true
  }
  // 监听编辑事件
  const onHandleEditClick = (row) => {
    // console.log(row)
    // 数据回显，将当前点击的行的数据存到表单数据中
    defualtModelFormData.value = { ...row }
    formModelRef.value.dialogTitle = '编辑'
    formModelRef.value.dialogVisible = true
  }
  return [formModelRef, defualtModelFormData, onHandleEditClick, onHandleNewClick]
}
